using System;
using System.Collections.ObjectModel;
using System.Text;
using Microsoft.VisualStudio.TeamSystem.Data.DataGenerator;

namespace MindFair.DevelopmentTools.CustomDataGenerators
{
    public enum TimeSpanUnits : int {Ticks = 0, Milliseconds, Seconds, Minutes, Hours, Days}

    public class DateSeries : Generator
    {
        private const int MinimumDateCount = 2;
        Collection<DateTime> _results = new Collection<DateTime> ();
        #region Constructors
        public DateSeries ()
        {
            _minimumStartDate = DateTime.MinValue;
            _maximumEndDate = DateTime.MaxValue;
            _minimumRange = TimeSpan.MinValue;
            _maximumRange = TimeSpan.FromDays (7);
        }
        #endregion
        #region Inputs
        private int _dateCount = MinimumDateCount;
        [Input (Name = "Number of Dates", DefaultValue = MinimumDateCount, Description = "")]
        public int DateCount
        {
            get { return _dateCount; }
            set
            {
                if (value >= MinimumDateCount)
                    _dateCount = value;
            }
        }
        private DateTime _minimumStartDate;
        [Input (Name = "Minimum Start Date",
            Description = "The earliest date the range can start on. This value must be less than the Maximum emd date. Must be greater than the Minimum Span Range.")]
        public DateTime MinimumStartDate
        {
            get { return _minimumStartDate; }
            set { _minimumStartDate = value; }
        }
        private DateTime _maximumEndDate;
        [Input (Name = "Maximum End Date",
            Description = "The latest date the range can end on. This value must be greater than the Minimum start date.")]
        public DateTime MaximumEndDate
        {
            get { return _maximumEndDate; }
            set { _maximumEndDate = value; }
        }
        private TimeSpan _minimumRange;
        [Input (Name = "Minimum Span Between Dates",
            Description = "The minimum amount of time between the start date and end date of the series. Must be less than the Maximum Span Range.")]
        public TimeSpan MinimumRange
        {
            get { return _minimumRange; }
            set { _minimumRange = value; }
        }
        private TimeSpan _maximumRange;
        [Input (Name = "Maximum Span Between Dates",
            Description = "The maximum amount of time between the start and end dates of the series. Must be greater than the Minimum Span Range.")]
        public TimeSpan MaximumRange
        {
            get { return _maximumRange; }
            set { _maximumRange = value; }
        }
        private TimeSpanUnits _intervalUnits;
        [Input (Name = "Interval Units",
            DefaultValue = TimeSpanUnits.Days,
            Description = "The unit of time to use for spacing between dates in the series. For example, when using 'Days', only whole days will be added to the initial start date.")]
        public TimeSpanUnits IntervalUnits
        {
            get { return _intervalUnits; }
            set { _intervalUnits = value; }
        }
        private int _selectedIndex;
        [Input (Name = "Selected Index",
            DefaultValue = 0,
            Description = "Zero-based index of the value to be used to populate the selected column. Must be at least zero (0) and less than the Number of Dates.")]
        public int SelectedIndex
        {
            get { return _selectedIndex; }
            set
            {
                if (value >= 0 && value < this.DateCount)
                    _selectedIndex = value;
            }
        }
        #endregion
        #region Outputs
        [Output (Name = "Start Date",
            Description = "The first date in the series.")]
        public DateTime StartDate
        {
            get { return _results[0]; }
        }
        [Output (Name = "Selected Date Value",
            Description = "The first date in the series.")]
        public DateTime SelectedValue
        {
            get { return _results[this.SelectedIndex]; }
        }
        [Output (Name = "End Date",
            Description = "The last date in the series.")]
        public DateTime EndDate
        {
            get { return _results[this._results.Count - 1]; }
        }
        #endregion
        #region OnGenerateNextValues
        protected override void OnGenerateNextValues ()
        {
            Random r = new Random (this.Seed);
            for (int ii = 0; ii < this.DateCount; ii++)
            {
                
            }
        }
        #endregion
    }
}
